<script>
	import config from './config'
	import store from '@/store'
	import {
		getToken
	} from '@/utils/auth'
	import {
		topList,
		list
	} from '@/common/api.js'
	export default {
		onLaunch: function() {
			this.initApp();
			// this.getMusic();
			this.getMenu();
		},
		methods: {
			// 初始化应用
			initApp() {
				// 初始化应用配置
				this.initConfig()
				// 检查用户登录状态
				//#ifdef H5
				this.checkLogin()
				//#endif
			},
			initConfig() {
				this.globalData.config = config
			},
			checkLogin() {
				if (!getToken()) {
					this.$tab.reLaunch('/pages/login')
				}
			},
			getMenu() {
				const array = [{
						iconPath: "/static/images/tabbar/home.png",
						selectedIconPath: "/static/images/tabbar/home_.png",
						text: '首页',
						count: 2,
						isDot: true,
						pagePath: "/pages/index"
					},
					{
						iconPath: "/static/images/tabbar/publish_.png",
						selectedIconPath: "/static/images/tabbar/publish_.png",
						text: '发布',
						midButton: true,
						pagePath: "/pages/publish/publish"
					},
					{
						iconPath: "/static/images/tabbar/mine.png",
						selectedIconPath: "/static/images/tabbar/mine_.png",
						text: '我的',
						pagePath: "/pages/mine/index"
					},
				]
				this.$store.commit("INIT_TABBAR", array);
			},
			async getMusic() {
				const awaitlist = await this.getMusicList();
				uni.setStorageSync('preloadedData', awaitlist);
				console.log(awaitlist)
				const ids = awaitlist.map(item => item.id);
				// 使用 Promise.all 处理并行的异步操作
				const musicList = await Promise.all(ids.map(async element => {
					const detail = await this.getMusicDetail(element);
					return detail;
				}));
				uni.setStorageSync('preloadedMusicDetailOfList', musicList);
				console.log(musicList)
			},
			getMusicDetail(id) {
				return new Promise((resolve, reject) => {
					list(id).then(res => {
						const result = res[1].data.data;
						if (result.code == '200') {
							resolve(result)
						} else {
							reject()
						}
					})
				})
			},
			getMusicList() {
				return new Promise((resolve, reject) => {
					topList().then((res) => {
						if (res.length) {
							resolve(res)
						} else {
							reject()
						}
					});
				})
			}
		}
	}
</script>

<style lang="scss">
	@import '@/static/scss/index.scss';
	/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
	@import "uview-ui/index.scss";

	.container {
		width: 100%;
		height: calc(100vh - 70px);
		overflow: hidden;
	}

	.container scroll-view {
		height: 100%;
	}

	.chat-custom-right {
		flex: 1;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		justify-content: space-between;
		align-items: flex-end;
	}

	.chat-custom-text {
		font-size: 12px;
		color: #999;
	}

	.fixbg {
		width: 100%;
		height: 100vh;
		position: fixed;
		top: 0;
		left: 0;
		background-size: cover;
		background-position: center 0;
		filter: blur(10px);
		transform: scale(1.2);
	}

	.fix-button-view {
		position: fixed;
		right: 25rpx;
		bottom: 175rpx;
		z-index: 1
	}

	.fix-button {
		width: 100rpx;
		height: 100rpx;
		border-radius: 50%;
		display: flex;
		align-items: center;
		justify-content: center;
		box-shadow: 0px 0px 10px 3px #1946B41A;
	}

	.fix-refresh-button-view {
		position: fixed;
		right: 25rpx;
		bottom: 25rpx;
		z-index: 1
	}

	.fix-refresh-button {
		width: 100rpx;
		height: 100rpx;
		border-radius: 50%;
		display: flex;
		align-items: center;
		justify-content: center;
		box-shadow: 0px 0px 10px 3px #1946B41A;
	}
</style>